﻿
@model VMC.Domain.Model.DataStructure.ComplexDataTypeManagement

@{
    //Do not change Actions Label because it has be the same accross all Views
    int LineNumber = 0;
    string linetype = "oddrow";
    string selected = "selected";
}


<table class="list-table" >
	
	<!-- Header Row with titles and ADD Button-->
    <tr class="header-row">
        <th  class="list-header-column"></th>
        <th  class="list-header-column">Name</th>
    <th  class="list-header-column" >
            <span class="action-buttons">
                @{
                    if (Model.AddEditModel != null && Model.Items.SelectedIndex == 0)
                    {
                        @VMCHelper.ActionIconButton(Url, 0, "Index", "Cancel" , "action-icon-cancel")
                    }
                }
                <a title="Show legends help" href="javascript:toggle_legends('_list_legends')" class="actionbutton"><span class="action-icon action-icon-show"></span></a>
                <a title="Add Complex Data Type" href="@Url.Action("Create")" class="actionbutton action-button with-text"><span class="action-icon action-icon-add"></span>Add</a>
            </span>
        </th>      
    </tr>
	
    <tr id="_list_legends" class="legends">
        <td colspan="2"> 
            <ul class="legends">
                <li><span class="action-icon action-icon-datatype"></span>Save/Update Changes</li>
                <li><span class="action-icon action-icon-delete"></span>Delete Data Type</li>
                <li><span class="action-icon action-icon-add"></span>Add new Data Type</li>
            </ul>            
        </td>
    </tr>
    @{
        if (Model.AddEditModel != null && Model.Items.SelectedIndex == 0)
        {        
	        <tr class="list-row edit-insert-row">
		        <td  class="list-column" colspan="3">
			        <div class="wide">
				        @Html.Partial("~/Views/DataTypes/_AddEditDataType.cshtml", @Model.AddEditModel)
			        </div>
		        </td>    
	        </tr>
        } 
    }

@foreach (var item in Model.Items.List.OrderBy(c => c.IsPublic)) { 

    LineNumber++;
    if (Model.Items.SelectedIndex == item.ID) { selected = "selected"; } else { selected = ""; }

    <tr class="list-row @linetype @selected">	
       <td class="list-column @if(selected=="selected") {<text>lborder</text> }">[@Html.DisplayFor(modelItem => item.VariableName)]</td>
       <td class="list-column">@Html.DisplayFor(modelItem => item.Name)</td>
       <td class="list-column @if(selected=="selected") {<text>rborder</text> }"> <span class="action-buttons">
            @if (Model.AddEditModel != null && Model.Items.SelectedIndex == item.ID)
            {
                @VMCHelper.ActionIconButton(Url, 0, "Index", "Cancel update", "action-icon-cancel")
            }
        @if (!item.IsPublic)
        {
            @VMCHelper.ActionIconButton(Url, @item.ID, "Update", "Update " + @item.Name, "action-icon-datatype")
            @VMCHelper.ActionIconButton(Url, @item.ID, "Columns", "Change columns for " + @item.Name, "action-icon-columns")
            @VMCHelper.ActionIconDeleteButton(Url, @item.ID, "Delete", "Delete " + @item.Name, "action-icon-delete", "Delete " + @item.Name, "Are you sure you want to delete " + @item.Name + " data type ?")
        }
    </span></td>
	</tr>
    
        if (item.Comment != null && item.Comment != "")
        {
            <tr class="list-row @linetype @selected">
            <td class="list-column  @if (selected == "selected")
                                    {<text>lborder rborder</text>}" colspan="3">@Html.DisplayFor(modelItem => item.Comment)</td>
            </tr>             
        }
        if (item.Description != null && item.Description != "")
        {
            <tr class="list-row @linetype @selected">
            <td class="list-column @if (selected == "selected")
                                   {<text>lborder rborder</text>}" colspan="3">@Html.DisplayFor(modelItem => item.Description)</td>
            </tr>             
        }
        if (Model.AddEditModel != null && Model.Items.SelectedIndex == item.ID)
        {        
	        <tr class="list-row edit-insert-row">
		        <td  class="list-column" colspan="3">
			        <div class="wide">
				        @Html.Partial("~/Views/DataTypes/_AddEditDataType.cshtml", @Model.AddEditModel)
			        </div>
		        </td>    
	        </tr>
        } 

        if (linetype == "oddrow") { linetype = "evenrow"; } else { linetype = "oddrow"; }
}

</table>

